package javazuoye.three;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/27 09:49
 */
public class _6_2_15 {
    public static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;

        TreeNode(char x) {
            val = x;
        }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode('a');
        root.left = new TreeNode('b');
        root.right = new TreeNode('c');
        root.left.left = new TreeNode('d');
        root.left.right = new TreeNode('e');
        root.right.left = new TreeNode('f');
        root.right.right = new TreeNode('g');
        System.out.println(cengci(root, 1));
        System.out.println(cengci(root, 2));
        System.out.println(cengci(root, 3));
        System.out.println(cengci(root, 4));
    }

    public static int cengci(TreeNode root, int n) {
        List<TreeNode> cList1 = new ArrayList<>();
        cList1.add(root);
        List<TreeNode> cList2 = new ArrayList<>();
        while (cList1.size() > 0) {
            n--;
            if (n == 0) {
                return cList1.size();
            }
            for (TreeNode now : cList1) {
                if (now.left != null) {
                    cList2.add(now.left);
                }
                if (now.right != null) {
                    cList2.add(now.right);
                }
            }
            cList1 = cList2;
            cList2 = new ArrayList<>();
        }
        return -1;
    }
}
